#include <cstdio>
#include <cstdlib>

int s, n, k, i, j;
int kx[1000][1000];
int tab[2][1000];

void read(){
	char a[2];
	scanf("%d %d", &n, &k);
	
	
	for(i=0;i<n;i++){
		for(j=0;j<k;j++){
			scanf("%s", a);
			if(a[0] >'9'){
				if(a[0]=='a') kx[i][j]=1;
				else kx[i][j]=10;
			}
			//else kx[i][j] = a[0] -'0';
			else kx[i][j] = atoi(a);
		}
	}
	/*/
	for(i=0;i<n;i++){
		for(j=0;j<k;j++)
			printf("%d ", kx[i][j] );
		printf("\n");
	}
	//*/
}
int melhor(int a, int b){
	return ((a>b)?(a<=s?a:b):(b<=s?b:a));
}

void process(){
	
	//*/
	int a=0, b=0;
	for(int z=0;z<n;z++){
		for(j=0;j<2;j++)for(i=0;i<s;i++)tab[j][i]=0;
			
		for(i=0;i<k;i++){
			a=i%2;
			b=(i+1)%2;
			for(j=0;j<kx[z][i];j++){
				tab[b][j]=tab[a][j];
			}
			tab[b][j]=kx[z][i];
			while(j++ < s){
				tab[b][j]=melhor(tab[b][j],kx[z][i]+tab[b][j-kx[z][i]]);
			}
		}
		printf("Jogador pensando:");
		for(i=1;i<=s;i++){
			printf( " %d", tab[b][i] );
		}
		printf("\n");
	}
	//*/
	
}

int main(){
	freopen("L4Q3.in","r",stdin);
	freopen("L4Q3.out","w",stdout);
	int x=1;
	while(scanf("%d", &s)==1){
		read();
		printf("Conjunto #%d\n", x++);
		process();
	}
}
